/*
 * Contributor(s): Yuan An yuan.an@ischool.drexel.edu
*/
package main.model;

import java.io.Serializable;
import java.util.ArrayList;

import y.base.Node;

import edu.stanford.smi.protegex.owl.model.OWLProperty;
import edu.stanford.smi.protegex.owl.model.RDFSDatatype;

/**Representation of an attribute of an entity node.
 * @author Yuan An
 */
public class Attribute implements OntoEle, Serializable{
	private Entity parent;
	private OWLProperty refProperty;
	private String name;
	private RDFSDatatype type;
	private Cardinality cardinality;
	private boolean isInverseFunctional;
	private boolean isInherited;
	private Object minValue;
	private Object maxValue;
	private ArrayList values;
	private boolean corresponded;
	
	//each attribute corresponds to a node in the ontology graph
	private Node refNode;

	public Attribute(OWLProperty refProperty, String name, RDFSDatatype type, Cardinality card) {
		parent=null;
		this.refProperty = refProperty;
		this.name = name;
		this.type = type;
		this.cardinality = card;
		isInverseFunctional = false;
		isInherited = false;
		minValue = null;
		maxValue = null;
		values = new ArrayList();
		corresponded=false;
		
		refNode = null;
	}

	public Attribute makeCopy(){
		Attribute ans=new Attribute(refProperty,name,type,cardinality);
		
		if(isInherited)
			ans.setInherited();
		if(isInverseFunctional)
			ans.setInverseFunctional();
		ans.setMaxValue(maxValue);
		ans.setMinValue(minValue);
		for(int i=0;i<values.size();i++)
			ans.addValue(values.get(i));
			
		return ans;	
	}
	
	//make an exact copy of this attribute. The difference from previous one
	//is that this one copies every things.
	public Attribute makeExactCopy(){
		Attribute ans=new Attribute(refProperty,name,type,cardinality);
		
		ans.setParent(parent);
		
		if(isInherited)
			ans.setInherited();
		if(isInverseFunctional)
			ans.setInverseFunctional();
		ans.setMaxValue(maxValue);
		ans.setMinValue(minValue);
		for(int i=0;i<values.size();i++)
			ans.addValue(values.get(i));
		if(corresponded)
			ans.setCorresponded();
					
		return ans;	
	}
	
	public Entity getParent(){
		return parent;	
	}
	
	public void setParent(Entity parent){
		this.parent = parent;
	}
	
	public String getName(){
		return name;
	}
	
	public OWLProperty getRefProperty() {
		return refProperty;
	}

	public RDFSDatatype getType() {
		return type;
	}

	public Cardinality getCardinality() {
		return cardinality;
	}

	public boolean isInverseFunctional() {
		return isInverseFunctional;
	}

	public boolean isInherited() {
		return isInherited;
	}

	public Object getMinValue() {
		return minValue;
	}

	public Object getMaxValue() {
		return maxValue;
	}

	public ArrayList getValues() {
		return values;
	}

	public void setType(RDFSDatatype type) {
		this.type = type;
	}

	public void setCardinality(Cardinality card) {
		cardinality = card;
	}

	public void setInverseFunctional() {
		isInverseFunctional = true;
	}

	public void setInherited() {
		isInherited = true;
	}

	public void setMinValue(Object value) {
		minValue = value;
	}

	public void setMaxValue(Object value) {
		maxValue = value;
	}

	public void addValue(Object value) {
		values.add(value);
	}
	
	public boolean isCorresponded(){
		return corresponded;
	}
	
	public void setCorresponded(){
		corresponded=true;
	}
	
	public void setNotCorresponded(){
		corresponded=false;
	}
	
	public Node getRefNode(){
		return refNode;
	}
	
	public void setRefNode(Node n){
		refNode = n;
	}
	
	public String display(){
		String ans = "";
		
		ans += "[" + parent.getName() + "]-";
		ans += "<" + name + ">";
		
		return ans;
	}
}
